package com.evil.common.application.enums.queue;

import com.evil.common.core.enums.RCodeEnum;
import com.evil.common.core.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 队列类型
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@AllArgsConstructor
public enum QueueTypeEnum {

    /**
     * 队列类型（1-应用订单导入，2-应用订单导出，3-套打模板）
     */
    APP_ORDER_IMPORT(1, "应用订单导入"),
    APP_ORDER_EXPORT(2, "应用订单导出"),
    PRINT_ORDER(3, "套打模板"),
    ;

    @Getter
    private final int id;
    @Getter
    private final String name;

    public static Optional<QueueTypeEnum> findById(Integer id) {
        if (null == id) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> e.id == id).findFirst();
    }

    public static QueueTypeEnum isExistById(Integer id) {
        return QueueTypeEnum.findById(id).orElseThrow(QueueTypeEnum::getBusinessException);
    }

    public static BusinessException getBusinessException() {
        return new BusinessException(RCodeEnum.ERROR_PARAMETER, "队列类型参数错误");
    }
}
